package com.wtz.temptest;

import java.sql.Time;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
 * @author tiezhu
 * Company dtstack
 * Date 2020/9/10 星期四
 */
public class TempDemo {
    private static final Pattern TIMESTAMP_PATTERN = Pattern.compile("^\\d+$");
    private static final Pattern TIME_FORMAT_PATTERN = Pattern.compile("\\w+\\d+:\\d+:\\d+");

    private static Pattern nestJsonFieldKeyPattern = Pattern.compile("(?i)((@*\\S+\\(.*\\)*\\S+)|((@*\\S+\\.)*\\S+))+\\s+(\\w+)\\s+AS\\s+(\\w+)(\\s+NOT\\s+NULL)?$");

    public static void main(String[] args) {
//        String data = "1599723937773";
//        String testData = "2020-2-4 19:32:49";
//        String testDataTime = "19:23:34";
//
//        convertToTimestamp(data);
//        convertToTimestamp(testData);
//
//        convertToTime(data);
//        convertToTime(testDataTime);
//
//        testArraysStream();
//        testString();
//        System.out.println("test");
        int c = 0;
        System.out.println((char) c);
    }

    private static void testArraysStream() {
        String[] testData = {"id", "name", "data"};

        String testStr = String.join(", ", testData);

        System.out.println(testStr);
    }

    private static void testString() {
        String[] test = {"a", "b", "c"};
        System.out.println("id, " + String.join(", ", test));
        List<String> data = new ArrayList<>();
        data.add("id");
        Collections.addAll(data, test);
        System.out.println(data);
        long l = Long.parseLong("1000");
        System.out.println(l);
        System.out.println(new Timestamp(1600070928506L));

        String testData = "";
        if (nestJsonFieldKeyPattern.matcher(testData).find()) {

        }

    }

    private static void convertToTimestamp(String data) {
        if (TIMESTAMP_PATTERN.matcher(data).find()) {
            System.out.println("TIME STAMP");
            System.out.println(new Timestamp(Long.parseLong(data)));
        }
        if (TIME_FORMAT_PATTERN.matcher(data).find()) {
            System.out.println("TIME FORMAT");
            System.out.println(Timestamp.valueOf(data));
        }
    }

    private static void convertToTime(String data) {
        if (TIMESTAMP_PATTERN.matcher(data).find()) {
            System.out.println("TIME STAMP");
            System.out.println(new Time(Long.parseLong(data)));
        }
        if (TIME_FORMAT_PATTERN.matcher(data).find()) {
            System.out.println("TIME FORMAT");
            System.out.println(Time.valueOf(data));
        }
    }

}
